package com.lihegang.example.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by dong-er on 2018/7/8.
 */
@RequestMapping("/web")
@Controller
public class WebController {

    private static final  Logger logger = LoggerFactory.getLogger(WebController.class);

    /**
     * 即是首页也测试redis集群
     * @param map
     * @param httpSession
     * @return
     */
    @RequestMapping(value = "/index")
    public String index(ModelMap map, HttpSession httpSession) {
        map.put("title", "第一个应用：sessionID=" + httpSession.getId());
        logger.info("sessionID=" + httpSession.getId());
        return "index";
    }


    @RequestMapping("thindex")
    public String thymeleafIndex(Model model){
        model.addAttribute("title","hello world");
        logger.info("这里是controller");
        return "thindex"; // 不要写成/index，会错错
    }

    @RequestMapping("jspindex")
    public String jspIndex(Model model){
        model.addAttribute("title","hello world");
        logger.info("这里是controller");
        return "jspindex"; // 不要写成/index，会错错
    }

    @RequestMapping("error")
    public String error(){
        throw new RuntimeException("测试错误页跳转");
    }

}
